package com.freeSoft;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.Properties;

public class DealConfig {
	Properties prop;
	String absolutePath;
	public Properties getProp() {
		return prop;
	}
	public void setProp(Properties prop) {
		this.prop = prop;
	}
	
	public void  generateWEBINFConfig(){
		createWebxml();
		createLog4JProperty();
		createApplicationXml();
		createStrutsXML();
		createRootPomXml();
		createCorePomXml();
		createWebPomXml();
		createProject();
		createClasspath();
		createSettings();
	}
	
	private void createSettings(){
		String outputDir = Util.getOutputDir(prop);
		String projectName = prop.getProperty(Util.PROJECT_NAME);
		String settingsPath  = outputDir+ projectName + File.separator+".settings";
		File f = new File(settingsPath);
		if ( !f.exists()){
			f.mkdirs();
		}
		try{
			String filepath = settingsPath+File.separator+"org.eclipse.core.resources.prefs";
			PrintWriter out	   = new PrintWriter(new BufferedWriter( new FileWriter(filepath)));
			out.println("outeclipse.preferences.version=1");
			out.println("encoding/<project>=UTF-8");
			out.flush();
			out.close();
			
			filepath=settingsPath+File.separator+"org.eclipse.jdt.core.prefs";
			out	   = new PrintWriter(new BufferedWriter( new FileWriter(filepath)));
			out.println("eclipse.preferences.version=1");
			out.println("org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled");
			out.println("org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5");
			out.println("org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve");
			out.println("org.eclipse.jdt.core.compiler.compliance=1.5");
			out.println("org.eclipse.jdt.core.compiler.debug.lineNumber=generate");
			out.println("org.eclipse.jdt.core.compiler.debug.localVariable=generate");
			out.println("org.eclipse.jdt.core.compiler.debug.sourceFile=generate");
			out.println("org.eclipse.jdt.core.compiler.problem.assertIdentifier=error");
			out.println("org.eclipse.jdt.core.compiler.problem.enumIdentifier=error");
			out.println("org.eclipse.jdt.core.compiler.source=1.5");
			out.flush();
			out.close();
			
			filepath=settingsPath+File.separator+"org.eclipse.wst.common.component";
			out	   = new PrintWriter(new BufferedWriter( new FileWriter(filepath)));
			out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
			out.println("<project-modules id=\"moduleCoreId\" project-version=\"1.5.0\">");
			out.println("<wb-module deploy-name=\""+projectName+"\">");
			out.println("<wb-resource deploy-path=\"/\" source-path=\"/"+projectName+Util.WEB_NAME+"/src/main/webapp\"/>");
			out.println("<wb-resource deploy-path=\"/WEB-INF/classes\" source-path=\"/"+projectName+Util.CORE_NAME+"/src/main/java\"/>");
			out.println("<wb-resource deploy-path=\"/WEB-INF/classes\" source-path=\"/"+projectName+Util.WEB_NAME+"/src/main/resources\"/>");
//			out.println("<wb-resource deploy-path=\"/WEB-INF/classes\" source-path=\"/"+projectName+Util.CORE_NAME+"/src/main/resources\"/>");
			out.println("<property name=\"context-root\" value=\""+projectName+"\"/>");
			out.println("<property name=\"java-output-path\"/>");
			out.println("</wb-module>");
			out.println("</project-modules>");
			out.flush();
			out.close();
			
			filepath=settingsPath+File.separator+"org.eclipse.wst.common.project.facet.core.xml";
			out	   = new PrintWriter(new BufferedWriter( new FileWriter(filepath)));
			out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
			out.println("<faceted-project>");
			out.println("<fixed facet=\"jst.web\"/>");
			out.println("<fixed facet=\"jst.java\"/>");
			out.println("<installed facet=\"wst.jsdt.web\" version=\"1.0\"/>");
			out.println("<installed facet=\"jst.web\" version=\"2.4\"/>");
			out.println("<installed facet=\"jst.java\" version=\"5.0\"/>");
			out.println("</faceted-project>");

			out.flush();
			out.close();
		}catch(Exception e) {
			System.out.println(e);
		}
	}
	private void createClasspath(){
		String outputDir = Util.getOutputDir(prop);
		String projectName = prop.getProperty(Util.PROJECT_NAME);
		String classpathPath  = outputDir+ projectName + File.separator+ ".classpath";
		try{
			PrintWriter out	   = new PrintWriter(new BufferedWriter( new FileWriter(classpathPath)));
			out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
			out.println("<classpath>");
			out.println("	<classpathentry kind=\"src\" path=\""+projectName+Util.CORE_NAME+"/src/main/java\"/>");
			out.println("	<classpathentry kind=\"src\" path=\""+projectName+Util.WEB_NAME+"/src/main/resources\"/>");
			out.println("	<classpathentry kind=\"con\" path=\"org.eclipse.jst.j2ee.internal.module.container\"/>");
			out.println("	<classpathentry kind=\"con\" path=\"org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER\">");
			out.println("		<attributes>");
			out.println("			<attribute name=\"org.eclipse.jst.component.dependency\" value=\"/WEB-INF/lib\"/>");
			out.println("		</attributes>");
			out.println("	</classpathentry>");
			out.println("	<classpathentry kind=\"con\" path=\"org.eclipse.jdt.launching.JRE_CONTAINER\">");
			out.println("		<attributes>");
			out.println("			<attribute name=\"owner.project.facets\" value=\"jst.java\"/>");
			out.println("		</attributes>");
			out.println("	</classpathentry>");
			out.println("	<classpathentry kind=\"con\" path=\"org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v5.5\"/>");
			out.println("	<classpathentry kind=\"output\" path=\"target/classes\"/>");
			out.println("</classpath>");
			out.flush();
			out.close();
		}catch(Exception e) {
			
		}
	}
	private void createProject(){
		String outputDir = Util.getOutputDir(prop);
		String projectName = prop.getProperty(Util.PROJECT_NAME);
		String projectPath  = outputDir+ projectName + File.separator+ ".project";
		try{
			PrintWriter out	   = new PrintWriter(new BufferedWriter( new FileWriter(projectPath)));
			out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
			out.println("<projectDescription>");
				out.println("	<name>"+projectName+"</name>");
				out.println("	<comment></comment>");
				out.println("	<projects>");
				out.println("	</projects>");
				out.println("	<buildSpec>");
				out.println("		<buildCommand>");
				out.println("			<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>");
				out.println("			<arguments>");
				out.println("			</arguments>");
				out.println("		</buildCommand>");
				out.println("		<buildCommand>");
				out.println("		<name>org.eclipse.jdt.core.javabuilder</name>");
				out.println("		<arguments>");
				out.println("		</arguments>");
				out.println("		</buildCommand>");
				out.println("		<buildCommand>");
				out.println("		<name>org.eclipse.wst.common.project.facet.core.builder</name>");
				out.println("		<arguments>");
				out.println("		</arguments>");
				out.println("		</buildCommand>");
				out.println("		<buildCommand>");
				out.println("		<name>org.eclipse.wst.validation.validationbuilder</name>");
				out.println("		<arguments>");
				out.println("		</arguments>");
				out.println("		</buildCommand>");
				out.println("		<buildCommand>");
				out.println("		<name>org.maven.ide.eclipse.maven2Builder</name>");
				out.println("		<arguments>");
				out.println("		</arguments>");
				out.println("		</buildCommand>");
				out.println("	</buildSpec>");
				out.println("	<natures>");
				out.println("		<nature>org.maven.ide.eclipse.maven2Nature</nature>");
				out.println("		<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>");
				out.println("		<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>");
				out.println("		<nature>org.eclipse.wst.common.project.facet.core.nature</nature>");
				out.println("		<nature>org.eclipse.jdt.core.javanature</nature>");
				out.println("		<nature>org.eclipse.wst.jsdt.core.jsNature</nature>");
				out.println("	</natures>");
				out.println("</projectDescription>");

			out.flush();
			out.close();
		}catch(Exception e) {
			System.out.println(e.toString());
		}
	}
	private void createWebPomXml(){
		String outputDir = Util.getOutputDir(prop);
		String projectName = prop.getProperty(Util.PROJECT_NAME);
		String corePath  = outputDir+ projectName + File.separator+ projectName+ Util.WEB_NAME +File.separator+ "pom.xml";
		try{
			PrintWriter out	   = new PrintWriter(new BufferedWriter( new FileWriter(corePath)));
			out.println("<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
			out.println("xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">");
			out.println("<modelVersion>4.0.0</modelVersion>");
			out.println("<parent>");
			out.println("	<groupId>"+projectName+"</groupId>");
			out.println("	<artifactId>"+projectName+"</artifactId>");
			out.println("	<version>1.0</version>");
			out.println("	<relativePath>../pom.xml</relativePath>");
			out.println("</parent>");
			out.println("<artifactId>"+projectName+Util.WEB_NAME+"</artifactId>");
			out.println("<packaging>war</packaging>");
			out.println("<name>Application - web</name>");
			out.println("<build></build>");
			out.println("<dependencies>");
			out.println("	<dependency>");
	        out.println("		<groupId>${pom.parent.groupId}</groupId>");
            out.println("		<artifactId>"+projectName+Util.CORE_NAME+"</artifactId>");
            out.println("		<version>${pom.parent.version}</version>");
            out.println("	</dependency>");
			out.println("</dependencies>");
			out.println("</project>");
			out.flush();
			out.close();
		}catch(Exception e) {
			
		}
	}
	private void createCorePomXml(){
		String outputDir = Util.getOutputDir(prop);
		String projectName = prop.getProperty(Util.PROJECT_NAME);
		String corePath  = outputDir+ projectName + File.separator+ projectName+ Util.CORE_NAME +File.separator+ "pom.xml";
		try{
			PrintWriter out	   = new PrintWriter(new BufferedWriter( new FileWriter(corePath)));
			out.println("<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
			out.println("xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">");
			out.println("<modelVersion>4.0.0</modelVersion>");
			out.println("<parent>");
			out.println("	<groupId>"+projectName+"</groupId>");
			out.println("	<artifactId>"+projectName+"</artifactId>");
			out.println("	<version>1.0</version>");
			out.println("	<relativePath>../pom.xml</relativePath>");
			out.println("</parent>");
			out.println("<artifactId>"+projectName+Util.CORE_NAME+"</artifactId>");
			out.println("<packaging>jar</packaging>");
			out.println("<name>Application - Core</name>");
			out.println("<build></build>");
			out.println("<dependencies>");
			out.println("	<dependency>");
			out.println("		<groupId>javax.servlet</groupId>");
			out.println("		<artifactId>jsp-api</artifactId>");
			out.println("		<version>2.0</version>");
			out.println("		<scope>provided</scope>");
			out.println("	</dependency>");
			out.println("	<dependency>");
			out.println("		<groupId>javax.servlet</groupId>");
			out.println("		<artifactId>servlet-api</artifactId>");
			out.println("		<version>2.4</version>");
			out.println("		<scope>provided</scope>");
			out.println("	</dependency>");
			writeDependency(out);
			out.println("</dependencies>");
			out.println("</project>");
			out.flush();
			out.close();
		}catch(Exception e) {
			System.out.println(e.toString());
		}
	}
	private void createRootPomXml(){
		String outputDir = Util.getOutputDir(prop);
		String projectName = prop.getProperty(Util.PROJECT_NAME);
		String rootPath = outputDir+ projectName + File.separator+ "pom.xml";
		try{
			PrintWriter out	   = new PrintWriter(new BufferedWriter( new FileWriter(rootPath)));
			out.println("<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
			out.println("xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">");
			out.println("<modelVersion>4.0.0</modelVersion>");
			out.println("<groupId>"+projectName+"</groupId>");
			out.println("<artifactId>"+projectName+"</artifactId>");
			out.println("<packaging>pom</packaging>");
			out.println("<version>1.0</version>");
			out.println("<modules>");
			out.println("<module>"+projectName+Util.CORE_NAME+"</module>");
			out.println("<module>"+projectName+Util.WEB_NAME+"</module>");
			out.println("</modules> ");
			out.println("<build>");
			out.println("	<plugins>");
			out.println("		<plugin>");
			out.println("		<artifactId>maven-compiler-plugin</artifactId>");
			out.println("			<version>2.0.2</version>");
			out.println("			<configuration>");
			out.println("				<source>1.5</source>");
			out.println("				<target>1.5</target>");
			out.println("			</configuration>");
			out.println("		</plugin>");
			out.println("	</plugins>");
			out.println("</build>");
			out.println("<dependencies>");
			writeDependency(out );
			out.println("</dependencies>");
			out.println("</project>");
			out.flush();
			out.close();
		}catch(Exception e) {
			System.out.println(e.toString());
		}
	}
	private void writeDependency(PrintWriter out){
		
		out.println("	<dependency>");
		out.println("		<groupId>com.opensymphony</groupId>");
		out.println("		<artifactId>xwork</artifactId>");
		out.println("		<version>2.1.3</version>");
		out.println("	</dependency>");
//		out.println("	<dependency>");
//		out.println("		<groupId>com.ibatis</groupId>");
//		out.println("		<artifactId>ibatis2-sqlmap</artifactId>");
//		out.println("		<version>2.1.7.597</version>");
//		out.println("	</dependency>");
		out.println("	<dependency>");
		out.println("		<groupId>org.apache.struts</groupId>");
		out.println("		<artifactId>struts2-core</artifactId>");
		out.println("		<version>2.1.8.1</version>");
		out.println("	</dependency>");
		out.println("	<dependency>");
		out.println("		<groupId>commons-lang</groupId>");
		out.println("		<artifactId>commons-lang</artifactId>");
		out.println("		<version>2.4</version>");
		out.println("	</dependency>");
		out.println("	<dependency>");
		out.println("		<groupId>org.springframework</groupId>");
		out.println("		<artifactId>spring</artifactId>");
		out.println("		<version>2.5.6</version>");
		out.println("	</dependency>");
		out.println("	<dependency>");
		out.println("		<groupId>org.apache.struts</groupId>");
		out.println("		<artifactId>struts2-json-plugin</artifactId>");
		out.println("		<version>2.1.8.1</version>");
		out.println("	</dependency>");
		out.println("	<dependency>");
	 	out.println("		<groupId>org.apache.struts</groupId>");
	  	out.println("		<artifactId>struts2-spring-plugin</artifactId>");
	  	out.println("		<version>2.1.8.1</version>");
	  	out.println("	</dependency>		");
	  	out.println("	<dependency>");
		out.println("		<groupId>jstl</groupId>");
		out.println("		<artifactId>jstl</artifactId>");
		out.println("		<version>1.1.2</version>");
		out.println("	</dependency>");
		out.println("	<dependency>");
		out.println("		<groupId>taglibs</groupId>");
		out.println("		<artifactId>standard</artifactId>");
		out.println("		<version>1.1.2</version>");
		out.println("	</dependency>");
		out.println("	<dependency>");
		out.println("		<groupId>log4j</groupId>");
		out.println("		<artifactId>log4j</artifactId>");
		out.println("		<version>1.2.9</version>");
		out.println("	</dependency>");
		out.println("	<dependency>");
		out.println("		<groupId>org.apache.struts</groupId>");
		out.println("		<artifactId>struts2-dojo-plugin</artifactId>");
		out.println("		<version>2.1.8.1</version>");
		out.println("	</dependency>");
		out.println("	<dependency>");
		out.println("		<groupId>net.sf.json-lib</groupId>");
		out.println("		<artifactId>json-lib</artifactId>");
		out.println("		<version>2.3</version>");
		out.println("		<classifier>jdk15</classifier>");
		out.println("	</dependency>");
		
	}
	private void createStrutsXML(){
		String outputDir = Util.getOutputDir(prop);
		String projectName = prop.getProperty(Util.PROJECT_NAME);
		String resourceAbsolutePath = outputDir+ projectName + File.separator+ projectName+ Util.WEB_NAME +File.separator+ 
		"src"+File.separator+"main"+File.separator+"resources"+File.separator;
		File f = new File(resourceAbsolutePath);
		if ( !f.exists()){
			f.mkdirs();
		}
		String strutsxmlPath = resourceAbsolutePath+"struts.xml";
		String strutsxmlPath2 = resourceAbsolutePath+"struts-"+projectName+".xml";
		try{
		PrintWriter out	   = new PrintWriter(new BufferedWriter( new FileWriter(strutsxmlPath)));
		out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		out.println("<!DOCTYPE struts PUBLIC \"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN\"");
		out.println("	\"http://struts.apache.org/dtds/struts-2.0.dtd\">");
		out.println("<struts>");
		out.println("<!-- Constants -->");
	    out.println("<constant name=\"struts.devMode\" value=\"false\"/>");
	    out.println("<constant name=\"struts.i18n.encoding\" value=\"UTF-8\"/>");
	    out.println("<constant name=\"struts.action.extension\" value=\"html\"/>");
	    out.println("<constant name=\"struts.objectFactory\" value=\"spring\"/>");
	    out.println("<constant name=\"struts.multipart.maxSize\" value=\"2097152\"/>");
	    out.println("<constant name=\"struts.ui.theme\" value=\"simple\"/>");
	    out.println("<include file=\"struts-"+projectName+".xml\"></include>");
	    out.println("<!-- ");
	    out.println("<constant name=\"struts.custom.i18n.resources\" value=\"ApplicationResources,errors\"/>");
	    out.println("<constant name=\"struts.ui.theme\" value=\"css_xhtml\"/>");
	    out.println("<constant name=\"struts.codebehind.pathPrefix\" value=\"/WEB-INF/pages/\"/>");
	    out.println("<constant name=\"struts.enable.SlashesInActionNames\" value=\"true\"/>");
	    out.println("-->");
	    out.println("<!-- Configuration for the default package. -->");
	    out.println("<package name=\"default\" extends=\"struts-default\">");
	    out.println("</package>");
	    out.println("</struts>");
	    out.flush();
	    out.close();
	    PrintWriter out2	   = new PrintWriter(new BufferedWriter( new FileWriter(strutsxmlPath2)));
	    out2.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
	    out2.println("<!DOCTYPE struts PUBLIC");
	    out2.println("\"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN\"");
	    out2.println("\"http://struts.apache.org/dtds/struts-2.0.dtd\">");
	    out2.println("<struts>");
	    out2.println("<package name=\""+projectName+"\" extends=\"struts-default\" namespace=\"/"+projectName+"\">");
   		out2.println("</package>");
    	out2.println("<package name=\"Struts2_AJAX_Mycompany\" extends=\"json-default\">");
    	out2.println("<!--<action name=\"jsonAction\" class=\"viewJsonAction\">");
	    out2.println("	<result type=\"json\"/>");
	    out2.println("	<result type=\"json\">");
	    out2.println("	<param name=\"root\">");
	    out2.println("		userList");
	    out2.println("	</param>");  
	    out2.println("	</result> ");
	    out2.println("	</action>");
	    out2.println("	<action name=\"demoForExtendJson\" class=\"demoForNoExtendJson\">");
	    out2.println("	<result type=\"json\"/>");
	    out2.println("	</action>");
	    out2.println("-->");
	    out2.println("</package>");
	    out2.println("</struts>");
	    out2.flush();
	    out2.close();
	    
		}catch(Exception e){
			System.out.println(e.toString());
		}
	}
	private void createLog4JProperty(){
		String path=absolutePath+File.separator+"log4j.properties";
		try {
			PrintWriter out	   = new PrintWriter(new BufferedWriter( new FileWriter(path)));
			out.println("log4j.rootLogger=info,stdout");
			out.println("log4j.appender.stdout=org.apache.log4j.ConsoleAppender");
			out.println("log4j.appender.stdout.layout=org.apache.log4j.PatternLayout");
			out.println("log4j.appender.stdout.layout.ConversionPattern=[ %p %d{yyyy-MM-dd HH:mm:ss} %c - %L - %M ] : %m%n ");
			out.flush();
			out.close();
		}catch(Exception e){
			System.out.println(e.toString());
		}
	}
	private void createApplicationXml(){
		String path=absolutePath+File.separator+"applicationContext.xml";
		try {
			PrintWriter out	   = new PrintWriter(new BufferedWriter( new FileWriter(path)));
//			out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
			out.println("<beans xmlns=\"http://www.springframework.org/schema/beans\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
			out.println("       xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd\"");
			out.println("default-lazy-init=\"true\">");
			out.println("<bean id=\"propertyConfigurer\"");
			out.println("	class=\"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer\">");
			out.println("	<property name=\"locations\">");
			out.println("					<list>");
			out.println("						<value>db.properties</value>");
			out.println("					</list>");
			out.println("	</property>");
			out.println("</bean>");
			out.println("<bean id=\"datasource\" class=\"org.apache.commons.dbcp.BasicDataSource\">");
			out.println("	<property name=\"driverClassName\" value=\"${jdbc.driverClassName}\" />");
			out.println("	<property name=\"url\" value=\"${jdbc.url}\" />");
			out.println("	<property name=\"username\" value=\"${jdbc.username}\" />");
			out.println("	<property name=\"password\" value=\"${jdbc.password}\" />");
			out.println("	<property name=\"maxActive\" value=\"40\" />");
			out.println("	<property name=\"maxIdle\" value=\"30\" />");
			out.println("	<property name=\"maxWait\" value=\"1000\" />");
			out.println("	<property name=\"defaultAutoCommit\" value=\"true\" />");
			out.println("	<property name=\"removeAbandoned\" value=\"true\" />");
			out.println("	<property name=\"removeAbandonedTimeout\" value=\"60\" />");
			out.println("</bean>");
			
			out.println("<bean id=\"jdbcTemplate\" class=\"org.springframework.jdbc.core.JdbcTemplate\">");
			out.println("	<property name=\"dataSource\">");
			out.println("	<ref bean=\"datasource\" />");
			out.println("	</property>");
			out.println("</bean>");
			
	    	out.println("</beans>");
			out.flush();
			out.close();
		}catch(Exception e){
			System.out.println(e.toString());
		}
	}
	private void createWebxml(){
		String outputDir = Util.getOutputDir(prop);
		String projectName = prop.getProperty(Util.PROJECT_NAME);
		absolutePath = outputDir+ projectName + File.separator+ projectName+ Util.WEB_NAME +File.separator+ 
		"src"+File.separator+"main"+File.separator+"webapp"+File.separator+"WEB-INF";
		File f = new File(absolutePath);
		if ( !f.exists()){
			f.mkdirs();
		}
		String webxmlPath = absolutePath+File.separator+"web.xml";
		File file = new File(webxmlPath);
		try {
			PrintWriter out	   = new PrintWriter(new BufferedWriter( new FileWriter(file)));
//			out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
			out.println("<web-app xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
			out.println("xmlns=\"http://java.sun.com/xml/ns/javaee\" xmlns:web=\"http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd\"");
			out.println("xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd\"");
			out.println("id=\"WebApp_ID\" version=\"2.5\">");
			out.println("<display-name>"+projectName+"</display-name>");
			out.println("<welcome-file-list>");
			out.println("	<welcome-file>index.html</welcome-file>");
			out.println("	<welcome-file>index.htm</welcome-file>");
			out.println("	<welcome-file>index.jsp</welcome-file>");
			out.println("	<welcome-file>default.html</welcome-file>");
			out.println("	<welcome-file>default.htm</welcome-file>");
			out.println("	<welcome-file>default.jsp</welcome-file>");
			out.println("</welcome-file-list>");
			out.println("<context-param>");
			out.println("	<param-name>webAppRootKey</param-name>");
			out.println("	<param-value>"+projectName+".root</param-value>");
			out.println("</context-param>");
			out.println("");
			out.println("<context-param>");
			out.println("	<param-name>log4jConfigLocation</param-name>");
			out.println("	<param-value>/WEB-INF/log4j.properties</param-value>");
			out.println("</context-param>");
			out.println("<context-param>");
			out.println("	<param-name>contextConfigLocation</param-name>");
			out.println("	<param-value>");
			out.println("		/WEB-INF/applicationContext.xml");
			out.println("	</param-value>");
			out.println("</context-param>");
			out.println("");
			out.println("<listener>");
			out.println("	<listener-class>org.springframework.web.context.ContextLoaderServlet</listener-class>");
			out.println("</listener>");
			out.println("<!-- ");
			out.println("<listener>");
			out.println("	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>");
			out.println("</listener>");
			out.println("-->");
			out.println("<listener>");
			out.println("	<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>");
			out.println("</listener>");
			out.println("<filter>");
			out.println("	<filter-name>encodingFilter</filter-name>");
			out.println(	"<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>");
			out.println("	<init-param>");
			out.println("		<param-name>encoding</param-name>");
			out.println("		<param-value>UTF-8</param-value>"); 
			out.println("	</init-param>");
			out.println("	<init-param>");
			out.println("		<param-name>forceEncoding</param-name>");
			out.println("		<param-value>true</param-value>");
			out.println("	</init-param>");
			out.println("</filter> ");
			out.println("<filter-mapping>");
			out.println("	<filter-name>encodingFilter</filter-name>");
			out.println("	<url-pattern>/*</url-pattern>");
			out.println("</filter-mapping>");
			out.println("<filter>");
			out.println("	<filter-name>struts</filter-name>");
			out.println("	<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>");
			out.println("</filter>");
			out.println("<filter-mapping>");
			out.println("	<filter-name>struts</filter-name>");
			out.println("	<url-pattern>/*</url-pattern>");
			out.println("</filter-mapping>");
			out.println("</web-app>");
			out.flush();
			out.close();
		}catch(Exception e){
			System.out.println(e.toString());
		}
	}
}
